package com.hqyj.yanguangzhi.service.impl;

import com.hqyj.common.pojo.BaseTopic;
import com.hqyj.common.pojo.ShortTopic;
import com.hqyj.common.util.CommonResult;
import com.hqyj.yanguangzhi.mapper.OEMapper;
import com.hqyj.yanguangzhi.mapper.OEShortTopicMapper;
import com.hqyj.yanguangzhi.service.OEService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.CustomAutowireConfigurer;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * YanGG
 *
 * @ClassName: OEServiceImpl
 * @author: yanguangzhi
 * @date: 2021/10/21 9:25
 */
@Service
public class OEServiceImpl implements OEService {
    private final static ConcurrentHashMap<String, Object> topic = new ConcurrentHashMap<>();

    @Resource
    private OEMapper oeMapper;

    @Resource
    private OEShortTopicMapper oeShortTopicMapper;

    @Override
    public CommonResult queryRandomTopic() {
        List<ShortTopic> shortTopics = oeShortTopicMapper.queryRandomShortTopic();
        List<BaseTopic> baseOneTopics = oeMapper.queryRandomBaseOneTopic();
        List<BaseTopic> baseTwoTopics = oeMapper.queryRandomBaseTwoTopic();
        List<BaseTopic> baseZeroTopics = oeMapper.queryRandomBaseThreeTopic();
        topic.put("baseOneTopics", baseOneTopics);
        topic.put("baseTwoTopics", baseTwoTopics);
        topic.put("shortTopics", shortTopics);
        topic.put("baseZeroTopics", baseZeroTopics);
        return new CommonResult(200, "题目加载成功！", topic);
    }

    @Override
    public CommonResult putAnsWer(String testPaperName, String one, String
            two, String zero, String shortTopic, Integer userId) {
        int i = oeMapper.putAnsWer(testPaperName, one, two, zero, shortTopic, userId);
        if (i == 0) {
            return new CommonResult(400, "提交失败");
        }
        return new CommonResult(200, "提交成功");
    }
}
